package com.newzqxq.koalamoney.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newzqxq.koalamoney.R;
import com.newzqxq.koalamoney.entity.BorrowInfoBean;
import com.newzqxq.koalamoney.entity.BorrowInfoBean;
import com.newzqxq.koalamoney.widget.ColorTextView;
import com.newzqxq.koalamoney.widget.progress.RoundProgress;

import java.util.List;

/**
 * 借款信息adapter
 * Created by ZQXQ-Developer on 2017/7/19.
 */

public class BorrowInfoAdapter extends BaseRecyclerAdapter {
    private List<BorrowInfoBean> items;
    private Context mContext;
    public OnItemClickListener mItemClickListener;
    private LayoutInflater inflater;

    public BorrowInfoAdapter(List<BorrowInfoBean> items, Context mContext) {
        this.items = items;
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(viewType, parent, false);
        return new mViewHolder(view, mItemClickListener);
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.item_borrow_info;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((mViewHolder) holder).bind(items.get(position));
    }

    @Override
    public int getItemCount() {
        return items == null ? 0 : items.size();
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view);
    }

    public BorrowInfoAdapter setmItemClickListener(OnItemClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
        return this;
    }

    private class mViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView tvBorrowData;//期数
        private TextView tvBorrowName;//名字/年龄
        private TextView tvBorrowMoney;//定投天数/金额
        private TextView tvBorrowDate;//天数
        private TextView tvBorrowType;
        private OnItemClickListener clickListener;
        private LinearLayout layout;

        public mViewHolder(View view, OnItemClickListener mItemClickListener) {
            super(view);
            tvBorrowData = (TextView) view.findViewById(R.id.tvBorrowData);
            tvBorrowName = (TextView) view.findViewById(R.id.tvBorrowName);
            tvBorrowMoney = (TextView) view.findViewById(R.id.tvBorrowMoney);
            tvBorrowDate = (TextView) view.findViewById(R.id.tvBorrowDate);
            tvBorrowType = (TextView) view.findViewById(R.id.tvBorrowType);
            this.clickListener = mItemClickListener;
            layout = (LinearLayout) view.findViewById(R.id.llBorrowParent);
            layout.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            if (clickListener != null) {
                clickListener.onItemClickListener(view);
            }
        }

        public void bind(BorrowInfoBean plan) {
            tvBorrowData.setText(plan.getPeriods());
            tvBorrowName.setText("借款人：" + plan.getName());
            tvBorrowMoney.setText(plan.getMoney());
            tvBorrowType.setText(plan.getType());
            tvBorrowDate.setText(plan.getDate());
        }
    }
}
